unit clsItem_ProdMaquina;

interface

uses dm, dbtables;

type
  TItem_ProdMaquina = class(TObject)
  public
    Quantidade: double;
    function Recuperar(Prod_Numero, Pro_Codigo, Sequencia, Cod_Maquina: string): boolean;
    function Recuperar1(Prod_Numero, Pro_Codigo, Cod_Maquina: string): boolean;
    function Recuperar2(Prod_Numero, Pro_Codigo, Sequencia: string): boolean;
    procedure Gravar(Prod_Numero, Pro_Codigo, Sequencia, Cod_Maquina: string);
    procedure Excluir(Prod_Numero: string);
    procedure Excluir_Itens(Prod_Numero, Pro_Codigo, Sequencia: string);
    procedure Excluir_Item(Prod_Numero, Pro_Codigo, Sequencia, Cod_Maquina: string);
    procedure Alterar_Qtde(Prod_Numero, Pro_Codigo, Sequencia: string);
  end;

implementation

procedure TItem_ProdMaquina.Gravar;
var
  tq: TQuery;
begin
  tq := Tquery.Create(DmInt);
  tq.databasename := dmint.Db.DatabaseName;
  tq.active := False;
  tq.sql.clear;
  tq.params.clear;
  tq.sql.add('Select * from Item_ProdMaquina where Prod_Numero=:a and Pro_Codigo=:b and ' +
    'Sequencia=:c and Cod_Maquina=:d');
  tq.params[0].asstring := Prod_Numero;
  tq.params[1].asstring := Pro_Codigo;
  tq.params[2].asstring := Sequencia;
  tq.params[3].asstring := Cod_Maquina;
  tq.open;
  if tq.eof then begin
    tq.close;
    tq.sql.clear;
    tq.params.clear;
    tq.sql.add('Insert into Item_ProdMaquina values (' +
      ':k_Prod_Numero,' +
      ':k_Pro_Codigo ,' +
      ':k_Sequencia  ,' +
      ':k_Cod_Maquina,' +
      ':k_Quantidade )');
  end else begin
    tq.close;
    tq.sql.clear;
    tq.params.clear;
    tq.sql.add('Update Item_ProdMaquina set    ' +
      'Quantidade =:k_Quantidade      ' +
      'where                          ' +
      'Prod_Numero=:k_Prod_Numero and ' +
      'Pro_Codigo =:k_Pro_codigo and  ' +
      'Sequencia  =:k_Sequencia and   ' +
      'Cod_Maquina=:k_Cod_Maquina     ');
  end;
  tq.parambyname('k_Prod_Numero').asstring := Prod_Numero;
  tq.parambyname('k_Pro_Codigo').asstring := Pro_Codigo;
  tq.parambyname('k_Sequencia').asstring := Sequencia;
  tq.parambyname('k_Cod_Maquina').asstring := Cod_Maquina;
  tq.parambyname('k_Quantidade').asfloat := Quantidade;
  tq.execsql;
  tq.close;
  tq.Free;
end;

procedure TItem_ProdMaquina.Excluir;
var
  tq: TQuery;
begin
  tq := Tquery.Create(dmint);
  tq.databasename := dmint.db.databasename;
  tq.active := False;
  tq.sql.Clear;
  tq.params.clear;
  tq.sql.add('Delete from Item_ProdMaquina where Prod_Numero=:a');
  tq.params[0].asstring := Prod_Numero;
  tq.execsql;
  tq.close;
  tq.Free;
end;

procedure TItem_ProdMaquina.Excluir_Itens;
var
  tq: TQuery;
begin
  tq := Tquery.Create(dmint);
  tq.databasename := dmint.db.databasename;
  tq.active := False;
  tq.sql.Clear;
  tq.params.clear;
  tq.sql.add('Delete from Item_ProdMaquina where Prod_Numero=:a and Pro_Codigo=:b and ' +
    'Sequencia=:c');
  tq.params[0].asstring := Prod_Numero;
  tq.params[1].asstring := Pro_Codigo;
  tq.params[2].asstring := Sequencia;
  tq.execsql;
  tq.close;
  tq.Free;
end;

procedure TItem_ProdMaquina.Alterar_Qtde;
var
  tq: TQuery;
begin
  tq := Tquery.Create(dmint);
  tq.databasename := dmint.db.databasename;
  tq.active := False;
  tq.sql.Clear;
  tq.params.clear;
  tq.sql.add('Update Item_ProdMaquina set Quantidade=:x where Prod_Numero=:a and ' +
    'Pro_Codigo=:b and Sequencia=:c');
  tq.params[0].asfloat := Quantidade;
  tq.params[1].asstring := Prod_Numero;
  tq.params[2].asstring := Pro_Codigo;
  tq.params[3].asstring := Sequencia;
  tq.execsql;
  tq.close;
  tq.Free;
end;

function TItem_ProdMaquina.Recuperar;
var
  tq: TQuery;
begin
  tq := Tquery.Create(DmInt);
  tq.databasename := dmint.Db.DatabaseName;
  tq.active := False;
  tq.sql.clear;
  tq.params.clear;
  tq.sql.add('Select * from Item_ProdMaquina where Prod_Numero=:a and Pro_Codigo=:b and ' +
    'Sequencia=:c and Cod_Maquina=:d');
  tq.params[0].asstring := Prod_Numero;
  tq.params[1].asstring := Pro_Codigo;
  tq.params[2].asstring := Sequencia;
  tq.params[3].asstring := Cod_Maquina;
  tq.open;
  Quantidade := tq.fieldbyname('Quantidade').asfloat;
  result := not tq.eof;
  tq.close;
  tq.free;
end;

function TItem_ProdMaquina.Recuperar1;
var
  tq: TQuery;
begin
  tq := Tquery.Create(DmInt);
  tq.databasename := dmint.Db.DatabaseName;
  tq.active := False;
  tq.sql.clear;
  tq.params.clear;
  tq.sql.add('Select * from Item_ProdMaquina where Prod_Numero=:a and Pro_Codigo=:b and ' +
    'Cod_Maquina=:c');
  tq.params[0].asstring := Prod_Numero;
  tq.params[1].asstring := Pro_Codigo;
  tq.params[2].asstring := Cod_Maquina;
  tq.open;
  Quantidade := tq.fieldbyname('Quantidade').asfloat;
  result := not tq.eof;
  tq.close;
  tq.free;
end;

procedure TItem_ProdMaquina.Excluir_Item;
var
  tq: TQuery;
begin
  tq := Tquery.Create(dmint);
  tq.databasename := dmint.db.databasename;
  tq.active := False;
  tq.sql.Clear;
  tq.params.clear;
  tq.sql.add('Delete from Item_ProdMaquina where Prod_Numero=:a and Pro_Codigo=:b and ' +
    'Sequencia=:c and Cod_Maquina=:d');
  tq.params[0].asstring := Prod_Numero;
  tq.params[1].asstring := Pro_Codigo;
  tq.params[2].asstring := Sequencia;
  tq.params[3].asstring := Cod_Maquina;
  tq.execsql;
  tq.close;
  tq.Free;
end;

function TItem_ProdMaquina.Recuperar2;
var
  tq: TQuery;
begin
  tq := Tquery.Create(DmInt);
  tq.databasename := dmint.Db.DatabaseName;
  tq.active := False;
  tq.sql.clear;
  tq.params.clear;
  tq.sql.add('Select * from Item_ProdMaquina where Prod_Numero=:a and Pro_Codigo=:b and ' +
    'Sequencia=:c');
  tq.params[0].asstring := Prod_Numero;
  tq.params[1].asstring := Pro_Codigo;
  tq.params[2].asstring := Sequencia;
  tq.open;
  Quantidade := tq.fieldbyname('Quantidade').asfloat;
  result := not tq.eof;
  tq.close;
  tq.free;
end;

end.

